<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="time"></div>
    <script>
        let time = document.querySelector('.time');
        let today = new Date(); //Date对象new 一个实例
        let show = function() {
            today.setTime(Date.now());
            let year = today.getFullYear();
            let month = today.getMonth() + 1; //月份从零开始记
            let day = today.getDate();
            day = String(day).padStart(2, 0);
            let hours = today.getHours();
            hours = String(hours).padStart(2, 0);
            let mm = today.getMinutes();
            mm = String(mm).padStart(2, 0);
            let ss = today.getSeconds();
            ss = String(ss).padStart(2, 0);
            let nowtime = `${year}年${month}月${day}日 ${hours}:${mm}:${ss}`
            time.innerHTML = nowtime;
            setInterval(show, 1000);
        }
        show();
    </script>
</body>

</html>